<template>
  <div class="productCenter">
    <div class="search-box">
      <el-input
        size="large"
        v-model="searchValue"
        placeholder="请输入"
        class="input-with-select"
      >
        <template #prepend>
          <el-select
            v-model="searchType"
            placeholder="请输入"
            style="width: 115px"
            size="large"
          >
            <el-option label="商品" value="1" />
            <el-option label="店铺" value="2" />
          </el-select>
        </template>
        <template #append>
          <el-button :icon="Search" @click="handleSearch" />
        </template>
      </el-input>
      <span class="shopCar">
        <span>我的购物车</span>
        <el-badge :value="0" class="item">
          <el-icon><ShoppingCartFull /></el-icon>
        </el-badge>
      </span>
    </div>
    <el-row>
      <el-col v-for="(item, index) in shopList" :key="index" :span="4">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="item.goodsUrl" class="image" @click="goDetail" />
          <div style="padding: 14px">
            <div class="price-box">
              ￥<span class="price">{{ item.goodsPrice }}</span>
            </div>
            <div class="desc">
              <span>{{ item.goodsBrand }}</span>
              <span
                >已售：{{
                  item.saleNum - 100000 >= 0 ? "10万+" : item.saleNum
                }}</span
              >
            </div>
            <div class="bottom">
              <div class="shopName-box">
                <el-icon><ShoppingBag /></el-icon>
                <span class="shopName">{{ item.shopName }}</span>
              </div>
              <el-icon><ShoppingCart /></el-icon>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { usersStore } from "@/store/users";
import {
  Search,
  ShoppingBag,
  ShoppingCart,
  ShoppingCartFull,
} from "@element-plus/icons-vue";
import { getGoodsList } from "@/api/productCenter";
import { onMounted, ref } from "vue";

// const currentDate = ref(new Date());
const shopList = ref();
const searchType = ref("1");
const searchValue = ref();
const store = usersStore();
// const { userInfo } = storeToRefs(store)
onMounted(async () => {
  getGoodsLists();
});

const handleSearch = () => {
  getGoodsLists();
};
const getGoodsLists = async () => {
  shopList.value = await getGoodsList({
    shopId: store.userInfo.shopId,
    searchType: searchType.value,
    searchValue: searchValue.value,
  });
};
const goDetail = () => {
  console.log(222222);
};
</script>

<style scoped lang="scss">
.productCenter {
  // background-color: #fff;
  width: 1350px;
  margin: auto;
  .search-box {
    line-height: 100px;
    height: 100px;
    background-image: url("~@/assets/img1.jpeg");
    text-align: center;
    .el-input {
      width: 800px;
    }
    .shopCar {
      font-size: 14px;
      color: #fff;
      display: inline-block;
      padding: 9px 18px;
      border: 1px solid #ccc;
      line-height: normal;
      vertical-align: middle;
      border-radius: 5px;
      background-color: rgba(255, 255, 255, 0.2);
      margin-left: 15px;
      cursor: pointer;
      .el-icon {
        vertical-align: bottom;
        font-size: 18px;
      }
    }
  }
  .el-row {
    justify-content: start;
    padding-top: 20px;
    padding-left: 10%;
    .el-col {
      margin-bottom: 20px;
      margin-right: 20px;
      &:nth-child(5n) {
        margin-right: 0px;
      }
    }
    .el-card {
      // width: 235px;
      .price-box {
        margin-bottom: 5px;
        font-size: 16px;
        .price {
          font-size: 24px;
          color: red;
        }
      }
      .desc {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .bottom {
        margin-top: 13px;
        line-height: 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .shopName-box {
          .el-icon {
            vertical-align: bottom;
            margin-right: 3px;
            font-size: 16px;
          }
        }
        & > .el-icon {
          vertical-align: bottom;
          margin-right: 3px;
          font-size: 16px;
          cursor: pointer;
        }
      }

      .button {
        padding: 0;
        min-height: auto;
      }

      .image {
        width: 100%;
        display: block;
        cursor: pointer;
      }
    }
  }
}
</style>
